package com.hdaccp.lettingagency.controller;

import com.hdaccp.lettingagency.dao.UserRoleDao;
import com.hdaccp.lettingagency.entity.Userinfo;
import com.hdaccp.lettingagency.service.UserInfoService;
import org.hibernate.validator.constraints.EAN;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/user")
@Scope("prototype")
public class UserInfoController {
    @Autowired
    private UserInfoService userInfoService ;
    @Autowired
    private UserRoleDao userRoleDao ;
    @RequestMapping("/getAll")
    @ResponseBody
    public List<Userinfo> getAll() {
        return userInfoService.getAll() ;
    }

    @RequestMapping("/queryAll")
    @ResponseBody
    public Map<String,Object> queryAll(int offset, int limit){
       /* Map<String,Object> map = new HashMap<>() ;
        map.put("rows",userInfoService.findAll(offset,limit)) ;
        map.put("total",userInfoService.findTotalCount()) ;
        return  map ;*/

       return  null ;
    }

    @RequestMapping("/querySearch")
    @ResponseBody
    public Map<String,Object> querySearch(String username,int offset, int limit){

        Map<String,Object> map = new HashMap<>() ;
        map.put("rows",userInfoService.findAll(username,offset,limit)) ;
        map.put("total",userInfoService.findTotalCount(username)) ;
        return  map ;

    }
    @RequestMapping("/doFenPei")
    @ResponseBody
    public   Map<String,Object> doFenPei(int userinfoid,int roleid){
        Map<String,Object> map = new HashMap<>() ;
        userRoleDao.update(userinfoid,roleid) ;
        map.put("rows",userInfoService.findAll("",0,2)) ;
        map.put("total",userInfoService.findTotalCount("")) ;
        return map;
    }
}
